import 'package:flutter/material.dart';
import 'package:flutter_application_1/models/Cart.dart';
import 'package:flutter_application_1/provider/user_provider.dart';

class CartProvider with ChangeNotifier {
  List<Cart> cartList;

  UserProvider? userProvider;

  CartProvider({
    this.cartList = const [],
    this.userProvider,
  });

  setCartList(List<Cart> data) {
    if (data.isEmpty) return;
    cartList = data;
    notifyListeners();
  }

  Future<dynamic> getCartList() async {
    if (userProvider == null || userProvider!.token.isEmpty) return;

    await Future.delayed(Duration(seconds: 1));

    setCartList([
      Cart(
        cartId: '1',
        goodsId: '1',
        name: '小米手机 小米9',
        price: 3999.99,
        number: 2,
      ),
      Cart(
        cartId: '2',
        goodsId: '2',
        name: '苹果笔记本',
        price: 13999.99,
        number: 1,
      ),
    ]);

    return cartList;
  }
}
